package org.lds.message.center.aliyun;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.lds.message.center.common.MessageHandler;
import org.lds.message.center.common.model.request.AliyunSmsRequest;
import org.lds.message.center.common.util.JsonUtil;

@Slf4j
@RequiredArgsConstructor
public class AliyunSmsHandler implements MessageHandler<AliyunSmsRequest> {
    private final Client aliyunSmsClient;

    @Override
    public void handle(AliyunSmsRequest request) throws Exception {
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setPhoneNumbers(request.getPhoneNumbers())
                .setSignName(request.getSignName())
                .setTemplateCode(request.getTemplateCode())
                .setTemplateParam(request.getTemplateParam());

        SendSmsResponse response = aliyunSmsClient.sendSms(sendSmsRequest);
        log.info("阿里云短信发送成功. request={} response={}", request, response == null ? null : JsonUtil.toJson(response.getBody()));
    }
}
